/**
 * @author Sebastian
 * @version 2.0
 * @date 2024/7/11 21:11
 */
// 路径总和
    // https://leetcode.cn/problems/path-sum/
public class Solution112 {
    public boolean hasPathSum(TreeNode root, int targetSum) {
        if (root == null) {
            return false;
        }
        targetSum -= root.val;
        if (root.left == null && root.right == null) {
            return targetSum == 0;
        }

        if (root.left != null) {
            boolean left = hasPathSum(root.left, targetSum);
            if (left) return true;
        }

        if (root.right != null) {
            boolean right = hasPathSum(root.right, targetSum);
            if (right) return true;
        }
        return false;
    }
}
